const config = {
  // 是否为测试环境
  // false 测试服务器
  // true 线上服务器
  ISONLINESERVER: false,
  // 测试服务器API地址
  TESTSERVER: 'http://manage.fenmio.com',
  // 正式服务器API地址
  ONLINESERVER: 'http://manage.fenmiaojinrong.com',
  // 页面返回前缀地址
  ONLINESERVERURL: 'http://m.fenmiaojinrong.com',
  TESTSERVERURL: 'http://m.fenmio.com'
}

const urlConfigs = [
  {
    key: 'RECHARGEACTION',                 // 充值提交的action地址
    padUrl: '/api/member/account/acctRecharge'
  },
  {
    key: 'RECHARGEOKRETURNURL',            // 充值成功后返回的页面地址
    padUrl: '/mine'
  },
  {
    key: 'OPENAUTHPOSTURL',                // 开户表单提交的地址
    padUrl: '/api/member/account/openAcct'
  },
  {
    key: 'OPENAUTHSUCCESSRETURNURL',       // 开户成功后返回的地址
    padUrl: '/successOpen'
  },
  {
    key: 'SINGNPOSTURL',                   // 签署提交的表单
    padUrl: '/api/member/account/authAcct'
  },
  {
    key: 'SIGNSUCCESSRETURNURL',           // 签署成功后返回的地址
    padUrl: '/successSign'
  }
]

const mapUrlGetter = (urlConfigs) => {
  const formURLS = ['RECHARGEACTION', 'OPENAUTHPOSTURL', 'SINGNPOSTURL']
  urlConfigs.forEach((urlObj) => {
    Object.defineProperty(config, urlObj.key, {
      get () {
        const isFormURL = formURLS.some((url) => urlObj.key === url)
        if (isFormURL) {
          return (config.ISONLINESERVER ? config.ONLINESERVER : config.TESTSERVER) + urlObj.padUrl
        } else {
          return (config.ISONLINESERVER ? config.ONLINESERVERURL : config.TESTSERVERURL) + urlObj.padUrl
        }
      },
      set (newValue) {
        return newValue
      },
      enumerable: true,
      configurable: true
    })
  })
}

mapUrlGetter(urlConfigs)

export default config
